package org.example.everyday;

import java.util.PriorityQueue;

public class LongestDiversetString {
    public static void main(String[] args) {
        int a = 1, b = 1, c = 7;
        LongestDiversetString l = new LongestDiversetString();
        String result = l.longestDierseString(a,b,c);
        System.out.println(result);
    }

    public String longestDierseString(int a,int b,int c){
        StringBuilder sb = new StringBuilder();
        PriorityQueue<int[]> q  = new PriorityQueue<>((x,y)->y[1] - x[1]);
        if(a>0){
            q.add(new int[]{0,a});
        }
        if(b>0){
            q.add(new int[]{1,b});
        }
        if(c>0){
            q.add(new int[]{2,c});
        }
        while (!q.isEmpty()){
            int[] cur = q.poll();
            int n = sb.length();
            if(n>=2 && sb.charAt(n-1) - 'a' == cur[0] && sb.charAt(n-2) - 'a' == cur[0]){
                if(q.isEmpty()){
                    break;
                }
                int[] next = q.poll();
                sb.append((char)(next[0] + 'a'));
                if( --next[1] != 0){
                    q.add(next);
                }
                q.add(cur);
            }else{
                sb.append((char)(cur[0] + 'a'));
                cur[1]--;
                if(cur[1] != 0){
                    q.add(cur);
                }
            }
        }
        return sb.toString();
    }
}
